﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    public class Cylinder : Geometry
    {
        public float x, y, z;
        P3 center;
        public Cylinder(float x, float y, float z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
            center = new P3(x, y, z);
        }
        public float distance(Ray rei)
        {
            
            float deltX = rei.direction.x;
            float deltY = rei.direction.y;
            float deltZ = rei.direction.z;
            float A = 2;
            float B = 2 * (deltX + deltY);
            float C = ((rei.origin.x * rei.origin.x) + (rei.origin.y * rei.origin.y) - 1);
            float T = (float)(-B - (Math.Sqrt((B*B)-4*A*C))/2*A);
            P3 p = rei.travel(T);
            normal(p);
            return T;
        }
        public P2 toP2(P3 p)
        {
            return new P2(0, 0);
        }
        public P3 normal(P3 p)
        {
            if (p.z == 1)
                return new P3(0, 0, 1);
            else if (p.z == -1)
                return new P3(0, 0, -1);
            else
                return new P3(p.x, p.y, 0);
        }
        /*
         * T = (-b +- sqrt(b^2-4ac))/2a
         * P = r.travel(t)
         * x^2 + y^2 = 1
         * (X! + TdeltX, Y! + TdeltY)
         * (X! + TdeltX)^2 + (Y! + TdeltY)^2 = 1
         * (X!^2 + 2TdeltX + T^2 + Y!^2 + 2TdeltY + T^2 = 1
         * A= 2
         * B = 2(deltX + deltY)
         * C = (X!^2 + Y!^2 - 1)
         * 2T^2 + 2(deltX + deltY)T + (X!^2 + Y!^2 - 1) = 0;
         * r = (X!, Y!, Z!)
         * (deltX,deltY,deltZ)
         * Z = Z! + TdeltZ
         * */
        
    }
}
